home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / DELPHI32 / GRAPHICS / TS32 / TS32.ZIP / SpriteEngine.int < prev    next >
Text File  |  1996-03-21  |  3KB  |  96 lines

  1. unit SpriteEngine;
  2.  
  3. (***************************************************
  4. TSpriteEngine->TComponent
  5.  
  6. Manages sprites on a TDIBDrawingSurfaces.
  7.  
  8. Properties
  9.  
  10. DIBDrawingSurface-
  11.   The TDIBDrawingSurface that will be used to Render
  12.   the sprites.
  13. DirtyRectangles-
  14.   Determines whether dirty rectangle processing will
  15.   be used to render to sprites.
  16. ExpectedSprites-
  17.   Set this to the number of sprites you expect to add.
  18.   It causes the sprite lists's Capacity property to
  19.   be initialized up front.
  20. Sprite[n]-
  21.   Returns a specific sprite.
  22. SpriteCount-
  23.   The number of registered sprites in the engine.
  24.  
  25. Events
  26.  
  27. OnCollision-
  28.   Triggered during the execution of the CollisionDetection
  29.   method.  Returns which two sprites have collided.
  30.  
  31. Methods
  32.  
  33. AddSprite-
  34.   Add a sprite to the engine.
  35. ChangeSpritePriority-
  36.   Safely changes the sprite's priority.  Use this
  37.   instead of changing the sprite's Priority property
  38.   directly.
  39. CollisionDetection-
  40.   Performs collision detection within the sprite
  41.   engine, or with another sprite engine.
  42. ProcessSprites-
  43.   Executes the Move routine of sprites, and does other
  44.   processing specific to dirty rectangle system.
  45. RenderSprites-
  46.   Draw sprites, using the sprites' Render method.  Call
  47.   this AFTER calling ProcessSprites.
  48. ***************************************************)
  49.  
  50. interface
  51.  
  52. uses
  53.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  54.   DIBDrawingSurface, Sprite, Grafix;
  55.  
  56. type
  57.  
  58.   TCollisionEvent = procedure( Sender: TObject; Sprite, TargetSprite: TSprite ) of object;
  59.  
  60.   TSpriteEngine = class( TComponent )
  61.   private
  62.      lstSprites: TList;
  63.      lstNewSprites: TList;
  64.      lstDeadSprites: TList;
  65.      lstDirty: TList;
  66.      FDDS: TDIBDrawingSurface;
  67.      FDirtyRectangles: boolean;
  68.      FExpectedSprites: integer;
  69.      FCollision: TCollisionEvent;
  70.      bDrawAll: boolean;
  71.   protected
  72.      function GetSprite( n: integer ): TSprite;
  73.      function GetSpriteCount: integer;
  74.      procedure SetExpectedSprites( n: integer );
  75.      procedure Notification( AComponent: TComponent; Operation: TOperation ); override;
  76.      procedure SetDirty( b: boolean );
  77.      procedure SetDDS( dds: TDIBDrawingSurface );
  78.   public
  79.      constructor Create( AOwner: TComponent ); override;
  80.      destructor Destroy; override;
  81.      procedure AddSprite( spr: TSprite );
  82.      procedure ChangeSpritePriority( spr: TSprite; n: integer );
  83.      procedure CollisionDetection( se: TSpriteEngine );
  84.      procedure ProcessSprites;
  85.      procedure RenderSprites;
  86.      procedure RemoveSprite( spr: TSprite );
  87.      property Sprite[n: integer]: TSprite read GetSprite;
  88.      property SpriteCount: integer read GetSpriteCount;
  89.   published
  90.      property DIBDrawingSurface: TDIBDrawingSurface read FDDS write SetDDS;
  91.      property DirtyRectangles: boolean read FDirtyRectangles write SetDirty;
  92.      property ExpectedSprites: integer read FExpectedSprites write SetExpectedSprites;
  93.      property OnCollision: TCollisionEvent read FCollision write FCollision;
  94.   end;
  95.  
  96. procedure Register;